<?php

namespace App\Livewire;

use App\Models\SessionsModel;
use Livewire\Attributes\Computed;
use Livewire\Component;

class SessionViewComponent extends Component
{
    public $id;

    public $perPage = 1;

    public function mount($id)
    {
        $this->id = $id;
    }

    public function loadMore()
    {
        $this->perPage = $this->perPage + 2;
    }

    #[Computed]
    public function commands()
    {
        return SessionsModel::query()->where('id', '=', $this->id)
            ->first()
            ->commands()
            ->orderBy('time')
            ->take($this->perPage)
            ->get();
    }

    #[Computed]
    public function commandsInfo()
    {
        return SessionsModel::query()->where('id', '=', $this->id)
            ->first()
            ->commands()
            ->orderBy('time')
            ->get();
    }

    #[Computed]
    public function session()
    {
        return SessionsModel::query()->where('id', '=', $this->id)
            ->first();
    }

    public function render()
    {
        return view('livewire.admin.session-view-component');
    }
}
